#ifndef TIMER_H_
#define TIMER_H_
/*******************************************************************************
 * File name:     timer.h
 * Description:   timer functions. To start timer user should:
 *                1. create configuration struct timerConf and set proper values:
 *                   struct timerConf tconf;
 *                   tconf.number = timer0;
 *                   tconf.priority = irqLOWEST_PRIORITY;
 *                   tconf.match[0].interrupt = matchINTRPT_ENABLE;
 *                   tconf.match[0].reset = matchRESET_ENABLE;
 *                   tconf.match[0].delay = 72000000;
 *                   tconf.match[0].matchService = timerService1;
 *                2. create object timer:
 *                   timer mytimer;
 *                3. call timerInit and assing its result to mytimer:
 *                   mytimer = timerInit(&tconf);
 *                4. call an event function:
 *                   timerMatchEnable(mytimer);
 * Project:       timer
 * Target:        LPC2478
 * Compiler:      arm-none-eabi-gcc
 * Date:          15-09-2011
 * Author:        Kuba
 * Based on:      NXP examples
 ******************************************************************************/

/*==============================================================================
 Includes
==============================================================================*/

/*==============================================================================
 Defines
==============================================================================*/

/*==============================================================================
 Types
==============================================================================*/
enum tmrNum {
   timer0 = 0,
   timer1 = 1,
   timer2 = 2,
   timer3 = 3
};

enum tmrPclk {
   timerPCLK_CORE_FREQ      = 0,    /* timer clock set to core frequency */
   timerPCLK_CORE_FREQ_DIV2 = 1,    /* timer clock set to core frequency/2 */
   timerPCLK_CORE_FREQ_DIV4 = 2,    /* timer clock set to core frequency/4 */
   timerPCLK_CORE_FREQ_DIV8 = 3,    /* timer clock set to core frequency/8 */
};

enum matchIntrpt {
   matchINTERRUPT_DISABLE ,
   matchINTERRUPT_ENABLE
};

enum matchReset {
   matchRESET_DISABLE,
   matchRESET_ENABLE
};

enum matchStop {
   matchSTOP_DISABLE,
   matchSTOP_ENABLE
};

struct timerMatch {
   enum matchIntrpt interrupt;         /* enable/disable interrupt */
   enum matchReset reset;              /* enable/disable reset */
   enum matchStop stop;                /* stop/don't stop counting */
   uint32 delay;                       /* delay in ticks */
   void (*matchService)(void);         /* user service called from ISR */
};

struct timerConf {
   enum tmrNum number;                 /* timer 0/1/2/3 */
   enum tmrPclk pclk;                  /* peripheral clock selection for timer */
   enum priority priority;             /* interrupt priority */
   struct timerMatch match[4];         /* 4 match events */
};

typedef struct timer* timer;
/*==============================================================================
 Global function prototypes
==============================================================================*/
timer timerInit (struct timerConf *timerConf);
void timerMatchEnable (timer tmr);

/*------------------------------------------------------------------------------
 function name:   timerGetPendingIntrpt
 description:     returns word that bits say which interrupt is pending:
                    0- MR0 interrupt flag for match channel 0
                    1- MR1 interrupt flag for match channel 1
                    2- MR2 interrupt flag for match channel 2
                    3- MR3 interrupt flag for match channel 3
                    4- CR0 interrupt flag for capture channel 0 event
                    5- CR1 interrupt flag for capture channel 1 event
                    6- CR2 interrupt flag for capture channel 2 event
                    7- CR3 interrupt flag for capture channel 3 event
 parameters:      none
 returned value:  uint8 word with pending interrupt bits
------------------------------------------------------------------------------*/

/******************************************************************************
* END OF FILE
******************************************************************************/



#endif /* TIMER_H_ */
